package com.jamal2362.apktool.fragment.files;

import android.view.View;
import android.widget.ImageView;
import com.jamal2362.apktool.fragment.EditorFragment;
import java.util.LinkedList;
import java.util.List;
import java.util.Collections;
import android.content.Context;
import com.jamal2362.apktool.ThemedActivity;

public class ErrorTree implements Comparable<ErrorTree>
{
	private final CharSequence msg;
	private final CharSequence details;
	protected EditorFragment editor;
	protected final List<ErrorTree> childs;

	public ErrorTree(CharSequence msg, CharSequence details)
	{
		this.msg = msg;
		this.details = details;
		this.editor = null;
		this.childs = new LinkedList<>();
	}

	public synchronized void setEditor(EditorFragment editor)
	{
		this.editor = editor;
		for (ErrorTree e : childs)
		{
			e.setEditor(editor);
		}
	}
	
	public Context getContext()
	{
		return ThemedActivity.INSTANCE.getBaseContext();
	}

	public CharSequence getMessage()
	{
		return msg;
	}
	
	public CharSequence getDetails()
	{
		return details;
	}
	
	public ErrorTree getChild(int idx)
	{
		return childs.get(idx);
	}
	
	public int getChildCount()
	{
		return childs.size();
	}
	
	public void click(View view)
	{}
	
	public synchronized void addChild(ErrorTree child)
	{
		childs.add(child);
		child.setEditor(editor);
	}
	
	public void reset()
	{
		childs.clear();
	}
	
	public void setIcon(ImageView icon)
	{}
	
	public void sort()
	{
		Collections.sort(childs);
	}

	@Override
	public int compareTo(ErrorTree p1)
	{
		return msg.toString().toLowerCase().compareTo(p1.msg.toString().toLowerCase());
	}
}
